package nature.nano.control.script.assembly;

import nature.nano.component.Strings;
import nature.nano.iface.Props;

class ClassParsingInfo {

	private final ClassStaticInfo origin;
	private final String name;
	private String slot;
	private final String slotAlias;
	private final String clazzAlias;
	private final boolean isAliasObject;
	
	public ClassParsingInfo(Props clazzProp, Props propsProp) {
		name = clazzProp.get(Strings.clazz);
		slotAlias = clazzProp.get(Strings.slotAlias);
		clazzAlias = clazzProp.get(Strings.clazzAlias);
		isAliasObject = false;
		
		origin = new ClassStaticInfo(name, propsProp);

		this.slot = clazzProp.get(Strings.slot);
		if (this.slot == null && origin != null) {
			this.slot = origin.getDefaultSlot();
		}
	}
	
	public ClassParsingInfo(ClassStaticInfo origin, String name, String slot, String slotAlias, String clazzAlias) {
		this.origin = origin;
		this.name = name;
		this.slot = slot;
		this.slotAlias = slotAlias;
		this.clazzAlias = clazzAlias;
		this.isAliasObject = true;
		
		if (this.slot == null && origin != null) {
			this.slot = origin.getDefaultSlot();
		}
	}
	
	public boolean valid() {
		return origin != null && origin.valid();
	}

	public boolean plug(ClassStaticInfo next) {
		if (slot == null) {
			return false;
		}
		return origin.plug(slot, next);
	}

	public ClassStaticInfo getOrigin() {
		return origin;
	}

	public String getSlot() {
		return slot;
	}
	
	public String getSlotAlias() {
		return slotAlias;
	}

	public String getClazzAlias() {
		return clazzAlias;
	}
	
	public String getName() {
		return name;
	}

	public boolean isAliasObject() {
		return isAliasObject;
	}
	
}
